package com.szd.qiongyou20.community.modle;

import android.util.Log;

import com.szd.qiongyou20.community.bean.RecommendBean;
import com.szd.qiongyou20.community.intefaces.ICommunity;
import com.szd.qiongyou20.utils.BaseUrl;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by SZD on 2016/12/29.
 */

public class LoadCommunityData implements LoadData {

    private ICommunity mICommunity;

    public LoadCommunityData() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BaseUrl.BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Log.i("", "LoadCommunityData: " + "是否执行");
        mICommunity = retrofit.create(ICommunity.class);
    }

    @Override
    public void ReconData(final LoadReconListener loadReconListener) {

        Call<RecommendBean> rconData = mICommunity.getRconData();

        rconData.enqueue(new Callback<RecommendBean>() {
            @Override
            public void onResponse(Call<RecommendBean> call, Response<RecommendBean> response) {
                if (response.isSuccess()) {
                    RecommendBean body = response.body();
                    loadReconListener.loadSuccess(body);
                }else{
                    Log.i("", "onResponse: " + "是否执行");
                }
            }

            @Override
            public void onFailure(Call<RecommendBean> call, Throwable t) {
                Log.i("???????", "onFailure: " + t.toString());
            }
        });
    }
}
